﻿using System;
using System.Collections.Generic;
using System.Text;
using flightquiz.Common;

namespace flightquiz.Data
{
    [Serializable]
    public class Answers : List<Answer>, IRender
    {
        public Answer Correct { get; set; }

        public void Add(string id, string title, string correct)
        {
            this.Add(id, title, id == correct);
        }

        public void Add(string id, string title, bool isCorrect)
        {
            if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(title))
            {
                bool found = false;
                foreach (var answer in this)
                {
                    if (answer.ID == id)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    this.Add(new Answer(id, title, isCorrect));
                }
            }
        }

        public string ToHTML()
        {
            string questionHtml = "";
            foreach (var answer in this)
            {
                questionHtml += answer.ToHTML();
                questionHtml += "<br/>";
            }

            return questionHtml;
        }
    }
}
